package com.cloud.gatewaySpringSecurity.properties;

import com.cloud.gatewaySpringSecurity.utils.RsaUtil;

import javax.annotation.PostConstruct;
import java.security.PrivateKey;
import java.security.PublicKey;

/**
 * @author zhozixiong
 * @date 2023/03/02
 *
 * 公私钥读取器
 */
public class RsaKeyProperties {

    private static final String pubKeyFile = "/gateway-springsecurity/src/main/resources/key/public_id";
    private static final String priKeyFile = "/gateway-springsecurity/src/main/resources/key/private_id";

    private PublicKey publicKey;
    private PrivateKey privateKey;

    @PostConstruct
    public void createRsaKey() throws Exception {
        publicKey = RsaUtil.getPublicKey(System.getProperty("user.dir") + pubKeyFile);
        privateKey = RsaUtil.getPrivateKey(System.getProperty("user.dir") + priKeyFile);
    }

    public PublicKey getPublicKey() {
        return this.publicKey;
    }

    public PrivateKey getPrivateKey() {
        return this.privateKey;
    }
}
